package com.wicket.okrbff.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrbff.biz.service.PlfAuthService;
import com.wicket.okrbff.biz.service.dto.common.BffFrameworkPrivacyDto;
import com.wicket.okrbff.biz.service.dto.req.AddCollectionRemoveExistingDataReqDto;
import com.wicket.okrbff.biz.service.dto.req.BatchClearUserInfoFromRedisReqDto;
import com.wicket.okrbff.biz.service.dto.req.CheckCollectionRemoveExistingDataReqDto;
import com.wicket.okrbff.biz.service.dto.req.*;
import com.wicket.okrbff.biz.service.dto.res.AddCollectionRemoveExistingDataRespDto;
import com.wicket.okrbff.biz.service.dto.res.BatchClearUserInfoFromRedisRespDto;
import com.wicket.okrbff.biz.service.dto.res.CheckCollectionRemoveExistingDataRespDto;
import com.wicket.okrbff.biz.service.dto.res.*;
import com.wicket.okrbff.biz.service.nb.NbPlfAuth;
import com.wicket.okrbff.common.util.CommonFunctionHelper;
import com.wicket.okrbff.common.util.RedisUtil;
import com.wicket.okrframework.integration.*;
import com.wicket.okrframework.integration.dto.*;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.stream.Collectors;
import com.wicket.okrbff.common.exception.Assert;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class PlfAuthServiceImpl implements PlfAuthService {

    @Resource
    FwBaseRoleClient roleClient;
    @Resource
    FwBasePlfAuthClient plfAuthClient;
    @Resource
    FwBaseInductionRecordClient inductionRecordClient;
    @Resource
    FwBasePowerClient powerClient;
    @Resource
    FwBaseDivineDataClient divineDataClient;
    @Resource
    NbPlfAuth nbPlfAuth;
    @Resource
    FwBasePlfAuthClient fwBasePlfAuthClient;
    @Resource
    FwBaseRoleClient fwBaseRoleClient;
    @Resource
    FwBasePowerClient fwBasePowerClient;
    @Resource
    FwBaseMemberClient fwBaseMemberClient;
    @Resource
    FwBaseInductionRecordClient fwBaseInductionRecordClient;
    @Resource
    FwBaseDivineDataClient fwBaseDivineDataClient;
    @Resource
    private RedisUtil redisUtil;

    /**
   * B1-2查询授权角色导航列表（管理）[1347]
   * gen by moon at 8/10/2022, 3:34:48 AM
   */
    @Trace(operationName = "B1-2查询授权角色导航列表（管理）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffQueryPltRoleAuthMenuListBorderRespDto queryPltRoleAuthMenuListBorder(BffQueryPltRoleAuthMenuListBorderReqDto reqDto){
      
       
       QueryRoleMenuListRespDto queryRoleMenuListRespDto_1 = null;
//步骤0: D1-2查询角色导航列表 - queryRoleMenuList
     QueryRoleMenuListRespDto queryRoleMenuListRespDto = null;
    QueryRoleMenuListReqDto queryRoleMenuListReqDto=new QueryRoleMenuListReqDto();
  
  
    /*D1-2查询角色导航列表[623]   */
    
      queryRoleMenuListRespDto = fwBaseRoleClient.queryRoleMenuList(queryRoleMenuListReqDto).getData();
      
      queryRoleMenuListRespDto_1 = queryRoleMenuListRespDto;
    
BffQueryPltRoleAuthMenuListBorderRespDto retData = new BffQueryPltRoleAuthMenuListBorderRespDto();
  if(queryRoleMenuListRespDto_1!=null){
      retData.setRoleList(queryRoleMenuListRespDto_1.getRoleList().stream().map(item -> BeanUtil.toBean(item, BffFrameworkSceneRoleDto.class)).collect(Collectors.toList()));//sourceId:31912_1
    }
  

  
  
return retData;
  }


    /**
   * B1-1查询权限授权列表（管理）[1452]
   * gen by moon at 8/17/2022, 7:39:29 PM
   */
    @Trace(operationName = "B1-1查询权限授权列表（管理）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffQueryPlfPowerAuthListRespDto queryPlfPowerAuthList(BffQueryPlfPowerAuthListReqDto reqDto){
      
       
       QueryPlfPowerAuthListRespDto queryPlfPowerAuthListRespDto_1 = null;
//步骤0: D1-1查权限授权列表 - queryPlfPowerAuthList
     QueryPlfPowerAuthListRespDto queryPlfPowerAuthListRespDto = null;
    QueryPlfPowerAuthListReqDto queryPlfPowerAuthListReqDto=new QueryPlfPowerAuthListReqDto();
  queryPlfPowerAuthListReqDto.setAuthorizedObject(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSceneId());//CURRENT_SCENEID//sourceId:35278_1
queryPlfPowerAuthListReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:35285_1
queryPlfPowerAuthListReqDto.setIsView("TRUE");//sourceId:230916_1
  
    /*D1-1查权限授权列表[1428]   */
    Assert.isNull(queryPlfPowerAuthListReqDto.getAuthorizedObject(),"B1-1查询权限授权列表（管理）-D1-1查权限授权列表-授权对象ID不能为空",false);
Assert.isNull(queryPlfPowerAuthListReqDto.getSubjectLifeCycle(),"B1-1查询权限授权列表（管理）-D1-1查权限授权列表-主体生命周期不能为空",false);
Assert.isNull(queryPlfPowerAuthListReqDto.getIsView(),"B1-1查询权限授权列表（管理）-D1-1查权限授权列表-空间是否可见不能为空",false);
      queryPlfPowerAuthListRespDto = fwBasePlfAuthClient.queryPlfPowerAuthList(queryPlfPowerAuthListReqDto).getData();
      
      queryPlfPowerAuthListRespDto_1 = queryPlfPowerAuthListRespDto;
    
BffQueryPlfPowerAuthListRespDto retData = new BffQueryPlfPowerAuthListRespDto();
  if(queryPlfPowerAuthListRespDto_1!=null){
      retData.setPlfAuthList(queryPlfPowerAuthListRespDto_1.getPlfAuthList().stream().map(item -> BeanUtil.toBean(item, BffPlfAuthDto.class)).collect(Collectors.toList()));//sourceId:35286_1
    }
  

  retData.setPageNum(queryPlfPowerAuthListRespDto.getPageNum());
        retData.setPageSize(queryPlfPowerAuthListRespDto.getPageSize());
        retData.setTotal(queryPlfPowerAuthListRespDto.getTotalNum());
        retData.setIsLastPage((Math.ceil(Double.valueOf(queryPlfPowerAuthListRespDto.getTotalNum()) / Double.valueOf(queryPlfPowerAuthListRespDto.getPageSize()))) <= retData.getPageNum());
        
  
return retData;
  }




    /**
   * B1-1查询角色授权列表（管理）[1079]
   * gen by moon at 8/10/2022, 3:32:22 AM
   */
    @Trace(operationName = "B1-1查询角色授权列表（管理）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffQueryPltRoleAuthListRespDto queryPltRoleAuthList(BffQueryPltRoleAuthListReqDto reqDto){
      
       
       QueryPltRoleAuthListRespDto queryPltRoleAuthListRespDto_1 = null;
//步骤0: D1-1查询角色授权列表 - queryPltRoleAuthList
     QueryPltRoleAuthListRespDto queryPltRoleAuthListRespDto = null;
    QueryPltRoleAuthListReqDto queryPltRoleAuthListReqDto=new QueryPltRoleAuthListReqDto();
  queryPltRoleAuthListReqDto.setAuthorizedObject(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSceneId());//CURRENT_SCENEID//sourceId:46095_1
queryPltRoleAuthListReqDto.setIsView("TRUE");//sourceId:160108_1
queryPltRoleAuthListReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:46100_1
queryPltRoleAuthListReqDto.setPlatformData("TRUE");//sourceId:46098_1
  
    /*D1-1查询角色授权列表[1434]   */
    
      queryPltRoleAuthListRespDto = fwBasePlfAuthClient.queryPltRoleAuthList(queryPltRoleAuthListReqDto).getData();
      
      queryPltRoleAuthListRespDto_1 = queryPltRoleAuthListRespDto;
    
BffQueryPltRoleAuthListRespDto retData = new BffQueryPltRoleAuthListRespDto();
  if(queryPltRoleAuthListRespDto_1!=null){
      retData.setPlfAuthList(queryPltRoleAuthListRespDto_1.getPlfAuthList().stream().map(item -> BeanUtil.toBean(item, BffPlfAuthDto.class)).collect(Collectors.toList()));//sourceId:46133_1
    }
  

  retData.setPageNum(queryPltRoleAuthListRespDto.getPageNum());
        retData.setPageSize(queryPltRoleAuthListRespDto.getPageSize());
        retData.setTotal(queryPltRoleAuthListRespDto.getTotalNum());
        retData.setIsLastPage((Math.ceil(Double.valueOf(queryPltRoleAuthListRespDto.getTotalNum()) / Double.valueOf(queryPltRoleAuthListRespDto.getPageSize()))) <= retData.getPageNum());
        
  
return retData;
  }



    /**
   * B1-1查询授权角色列表（边界）[1596]
   * gen by moon at 8/10/2022, 3:36:15 AM
   */
    @Trace(operationName = "B1-1查询授权角色列表（边界）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffQueryPltAuthRoleListBorderRespDto queryPltAuthRoleListBorder(BffQueryPltAuthRoleListBorderReqDto reqDto){
      
       
       QueryPltAuthRoleListRespDto queryPltAuthRoleListRespDto_1 = null;
//步骤0: D1-1查询授权角色列表（边界） - queryPltAuthRoleList
     QueryPltAuthRoleListRespDto queryPltAuthRoleListRespDto = null;
    QueryPltAuthRoleListReqDto queryPltAuthRoleListReqDto=new QueryPltAuthRoleListReqDto();
  
  
    /*D1-1查询授权角色列表（边界）[1594]   */
    
      queryPltAuthRoleListRespDto = fwBasePlfAuthClient.queryPltAuthRoleList(queryPltAuthRoleListReqDto).getData();
      
      queryPltAuthRoleListRespDto_1 = queryPltAuthRoleListRespDto;
    
BffQueryPltAuthRoleListBorderRespDto retData = new BffQueryPltAuthRoleListBorderRespDto();
  if(queryPltAuthRoleListRespDto_1!=null){
      retData.setRoleList(queryPltAuthRoleListRespDto_1.getRoleList().stream().map(item -> BeanUtil.toBean(item, BffFrameworkSceneRoleDto.class)).collect(Collectors.toList()));//sourceId:46153_1
    }
  

  
  
return retData;
  }

    /**
   * B1-2查询授权权限列表（边界）[1453]
   * gen by moon at 8/18/2022, 10:49:45 PM
   */
    @Trace(operationName = "B1-2查询授权权限列表（边界）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffQueryPltAuthPowerListBorderRespDto queryPltAuthPowerListBorder(BffQueryPltAuthPowerListBorderReqDto reqDto){
      
       
       QueryPltAuthPowerListRespDto queryPltAuthPowerListRespDto_1 = null;
//步骤0: D1-1查询授权权限列表（边界） - queryPltAuthPowerList
     QueryPltAuthPowerListRespDto queryPltAuthPowerListRespDto = null;
    QueryPltAuthPowerListReqDto queryPltAuthPowerListReqDto=new QueryPltAuthPowerListReqDto();
  if(reqDto!=null){
      queryPltAuthPowerListReqDto.setStrategyType(reqDto.getStrategyType());//sourceId:45494_1
    }
  
    /*D1-1查询授权权限列表（边界）[1574]   */
    Assert.isNull(queryPltAuthPowerListReqDto.getStrategyType(),"B1-2查询授权权限列表（边界）-D1-1查询授权权限列表（边界）-分配策略不能为空",false);
      queryPltAuthPowerListRespDto = fwBasePlfAuthClient.queryPltAuthPowerList(queryPltAuthPowerListReqDto).getData();
      
      queryPltAuthPowerListRespDto_1 = queryPltAuthPowerListRespDto;
    
BffQueryPltAuthPowerListBorderRespDto retData = new BffQueryPltAuthPowerListBorderRespDto();
  if(queryPltAuthPowerListRespDto_1!=null){
      retData.setFrameworkPrivacyList(queryPltAuthPowerListRespDto_1.getFrameworkPrivacyList().stream().map(item -> BeanUtil.toBean(item, BffFrameworkPrivacyDto.class)).collect(Collectors.toList()));//sourceId:45497_1
    }
  

  
  
return retData;
  }
/**
   * B1-1存档平台权限授权（平台）[595]
   * gen by moon at 8/10/2022, 3:29:31 AM
   */
    @Trace(operationName = "B1-1存档平台权限授权（平台）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffArchivePlfPowerAuthRespDto archivePlfPowerAuth(BffArchivePlfPowerAuthReqDto reqDto){
      
       
       //步骤0: D1-1存档权限授权 - archivePlfPowerAuth
     ArchivePlfPowerAuthRespDto archivePlfPowerAuthRespDto = null;
    ArchivePlfPowerAuthReqDto archivePlfPowerAuthReqDto=new ArchivePlfPowerAuthReqDto();
  if(reqDto!=null){
      archivePlfPowerAuthReqDto.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//sourceId:51824_1
    }
  
    /*D1-1存档权限授权[1562]   */
    Assert.isNull(archivePlfPowerAuthReqDto.getPlatformAuthorizeId(),"B1-1存档平台权限授权（平台）-D1-1存档权限授权-授权记录ID不能为空",false);
      archivePlfPowerAuthRespDto = fwBasePlfAuthClient.archivePlfPowerAuth(archivePlfPowerAuthReqDto).getData();
      
      
    
//步骤1: D1-1查询权限授权详情 - queryPlfPowerAuthDetail
     QueryPlfPowerAuthDetailRespDto queryPlfPowerAuthDetailRespDto = null;
    QueryPlfPowerAuthDetailReqDto queryPlfPowerAuthDetailReqDto=new QueryPlfPowerAuthDetailReqDto();
  if(reqDto!=null){
      queryPlfPowerAuthDetailReqDto.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//sourceId:52785_1
    }
  
    /*D1-1查询权限授权详情[581]   */
    Assert.isNull(queryPlfPowerAuthDetailReqDto.getPlatformAuthorizeId(),"B1-1存档平台权限授权（平台）-D1-1查询权限授权详情-授权记录ID不能为空",false);
      queryPlfPowerAuthDetailRespDto = fwBasePlfAuthClient.queryPlfPowerAuthDetail(queryPlfPowerAuthDetailReqDto).getData();
      
      
    
//步骤2: D1-存档权限分配缓存 - archiveTributPowerRedis
     ArchiveTributPowerRedisRespDto archiveTributPowerRedisRespDto = null;
    if(queryPlfPowerAuthDetailRespDto !=null){
          ArchiveTributPowerRedisReqDto archiveTributPowerRedisReqDto=new ArchiveTributPowerRedisReqDto();
  if(queryPlfPowerAuthDetailRespDto!=null){
      archiveTributPowerRedisReqDto.setPrivacyId(queryPlfPowerAuthDetailRespDto.getAuthorizedContentId());//sourceId:52809_1
    }
  
    /*D1-存档权限分配缓存[1725]   */
    Assert.isNull(archiveTributPowerRedisReqDto.getPrivacyId(),"B1-1存档平台权限授权（平台）-D1-存档权限分配缓存-权限ID不能为空",false);
      archiveTributPowerRedisRespDto = fwBasePowerClient.archiveTributPowerRedis(archiveTributPowerRedisReqDto).getData();
      
      
           }
    
BffArchivePlfPowerAuthRespDto retData = new BffArchivePlfPowerAuthRespDto();
  
  

  
  
return retData;
  }

}
